package com.heny.demo.common;

import java.util.Map;
/**
 * @author litao.cc
 * @version CommonResult.java v0.1 t2025/4/24 1:02
 * @date 2025/4/24 1:02
 * @description CommonResult
 */
public class CommonResult<T> {
    private boolean success;
    private String errorCode;

    private String errorMessage;

    private T data;

    private Map<String, Object> extData;

    public CommonResult(){}

    public CommonResult(boolean success) {
        this.success = success;
    }

    /**
      * @param success
     * @param errorCode
     * @param errorMessage
     */
    public CommonResult(boolean success, String errorCode, String errorMessage) {
        this.success = success;
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    /**
     * @param success
     * @param data
     */
    public CommonResult(boolean success, T data) {
        this.success = success;
        this.data = data;
    }

    public static <T> CommonResult<T> ofSuccess(){
        return new CommonResult<T>(true);
    }
    public static <T> CommonResult<T> ofSuccess(T data){
        return new CommonResult<T>(true,data);

    }
    public static <T> CommonResult<T> ofFailure(){
        return new CommonResult<T>(false);
    }
    public static <T> CommonResult<T> ofFailure(String errorCode, String errorMessage){
        return new CommonResult<T>(false,errorCode,errorMessage);
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Map<String, Object> getExtData() {
        return extData;
    }

    public void setExtData(Map<String, Object> extData) {
        this.extData = extData;
    }
}
